import useUserStore from '@/store/modules/user'

const permission = {
  mounted(el, binding) {
    const userStore = useUserStore()
    const { value } = binding
    
    if (value && Array.isArray(value)) {
      const hasPermission = value.some(role => userStore.roles.includes(role))
      if (!hasPermission) {
        el.parentNode?.removeChild(el)
      }
    } else {
      throw new Error(`需要指定权限数组，如 v-permission="['admin']"`)
    }
  }
}
export default permission